<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>美国职业篮球联盟(NBA)球员信息</title>
</head>
<body>
<h1>美国职业篮球联盟(NBA)球员信息</h1>
<form method="get" action="${pageContext.request.contextPath}/list">
    <p>
        球员姓名：<input type="text" name="pname">&nbsp;&nbsp;
        所属球队：
        <select name="cid">
            <option value="0">-请选择-</option>
            <option value="1">湖人</option>
            <option value="2">火箭</option>
            <option value="3">凯尔特人</option>
            <option value="4">骑士</option>
            <option value="5">马刺</option>
            <option value="6">魔术</option>
            <option value="7">太阳</option>
            <option value="8">勇士</option>
        </select>
        <input type="submit" value="查询">&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" onclick="add()" value="添加新球员信息">
    </p>
    <table border="1" style="text-align: center">
        <tr style="background-color: #ccc">
            <th>球员编号</th>
            <th>球员名称</th>
            <th>出生时间(yyyy-MM-dd)</th>
            <th>球员身高(单位：cm)</th>
            <th>球员体重(单位：kg)</th>
            <th>球员位置</th>
            <th>所属球队</th>
            <th>相关操作</th>
        </tr>
        <c:forEach items="${list}" var="players">
            <tr>
                <td>${players.pid}</td>
                <td>${players.pname}</td>
                <td><fmt:formatDate value='${players.birthday}' pattern='yyyy-MM-dd'/></td>
                <td>${players.height}</td>
                <td>${players.weight}</td>
                <td>${players.position}</td>
                <td>
                    <c:if test="${players.cid==1}">
                        <c:out value="湖人">湖人</c:out>
                    </c:if>
                    <c:if test="${players.cid==2}">
                        <c:out value="火箭">火箭</c:out>
                    </c:if>
                    <c:if test="${players.cid==3}">
                        <c:out value="凯尔特人">凯尔特人</c:out>
                    </c:if>
                    <c:if test="${players.cid==4}">
                        <c:out value="骑士">骑士</c:out>
                    </c:if>
                    <c:if test="${players.cid==5}">
                        <c:out value="马刺">马刺</c:out>
                    </c:if>
                    <c:if test="${players.cid==6}">
                        <c:out value="魔术">魔术</c:out>
                    </c:if>
                    <c:if test="${players.cid==7}">
                        <c:out value="太阳">太阳</c:out>
                    </c:if>
                    <c:if test="${players.cid==8}">
                        <c:out value="勇士">勇士</c:out>
                    </c:if>
                </td>

                <td>
                    <a href="${pageContext.request.contextPath}/byId?id=${players.pid}">修改</a>
                    <a href="JavaScript:void(0)" onclick="del(${players.pid})">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    
</form>

<script>
    function del(id){
        let con=confirm('确认要删除吗？')

        if (con){
            location='delete?id='+id;
        }
    }

    function add(){
        location='add';
    }
</script>
</body>
</html>
